package j.framework.core;

import j.util.New;

import java.util.List;

/**
 * 业务表数据的变更实体类
 * Created by junhai on 2015/4/5.
 */
public class ChangedData implements java.io.Serializable {

    public static List<ChangedData> buildSingleChangedData(String fieldName,String oldValue,String newValue){
        List<ChangedData> list = New.list();
        ChangedData changedData = new ChangedData();
        changedData.setFieldName(fieldName);
        changedData.setOldValue(oldValue);
        changedData.setNewValue(newValue);
        list.add(changedData);
        return list;
    }

    public static ChangedData buildChangedData(String fieldName,String oldValue,String newValue){
        ChangedData changedData = new ChangedData();
        changedData.setFieldName(fieldName);
        changedData.setOldValue(oldValue);
        changedData.setNewValue(newValue);
        return changedData;
    }

    private String fieldName;
    private String oldValue;
    private String newValue;

    public String getFieldName() {
        return fieldName;
    }
    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getOldValue() {
        return oldValue;
    }
    public void setOldValue(String oldValue) {
        this.oldValue = oldValue;
    }

    public String getNewValue() {
        return newValue;
    }
    public void setNewValue(String newValue) {
        this.newValue = newValue;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ChangedData that = (ChangedData) o;

        if (fieldName != null ? !fieldName.equals(that.fieldName) : that.fieldName != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return fieldName != null ? fieldName.hashCode() : 0;
    }
}
